<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<html>
<head>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/meta.jsp"%>
<%@include file="/common/validator.jsp"%>
<script type="text/javascript" src="${ctx}/scripts/fckeditor/fckeditor.js"></script>
<style type="text/css">
	.check{
		border:0px;
	}
</style>
</head>
<body>
<div class="x-panel">
<div class="x-panel-header">编辑图书信息</div>
<div class="x-toolbar">
<table width="100%">
      <tr>
        <td align="right" height="22">
          <a href="${ctx}/book/index.do"><img src="${ctx}/images/icons/house.gif"/> 图书列表</a>
        </td>
      </tr>
    </table>
</div>
<table width="100%" border="0" cellpadding="5" cellspacing="1">
	<tr>
		<td><%@ include file="/common/messages.jsp"%></td>
	</tr>
</table>
<div class="x-panel-body">
<s:hidden id="bkType" name="model.bkType"/>
<s:form id="bookForm" action="save.do" method="post" theme="simple" validate="true" enctype="multipart/form-data">
<table width="900" align="center">
	<tr>
		<td align="center">
			<s:hidden id="bookId" name="model.id" />
			<fieldset style="margin: 10px;"><legend>编辑图书信息</legend>
			<table id="mytable" align="center" border="0">
				<tr>
					<td valign="top">
					  <table width="550" height="300" align="left" border="0" cellspacing="1">
						<tr>
							<td style="height: 6px;" colspan="4"></td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">图书名称：</td>
							<td align="left" colspan="3">
							  <s:textfield id="name" name="model.name" cssClass="required" cssStyle="width:380px" />
							<font color="red">*</font></td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">出版社：</td>
							<td align="left" colspan="3">
								<s:select id="pressId" name="model.press.id" list="pressList" listKey="prId" listValue="prName"
										headerKey="1" headerValue="--选择出版社--" cssStyle="width:383px; height:500px;" />
							</td>
						</tr>
						<tr>								
							<td width="93" align="right" height="22">作 者：</td>
							<td width="152" align="left">
							  <s:textfield id="author" name="model.author" /></td>
							<td align="right" width="93" height="22">类 型：</td>
							<td width="214" align="left">
								<INPUT type="checkbox" name="bkTypes" value="1" class="check"><span style="color:blue;">新书</span>
								<INPUT type="checkbox" name="bkTypes" value="2" class="check"><span style="color:green;">热销</span>
								<INPUT type="checkbox" name="bkTypes" value="3" class="check"><span style="color:red;">特价</span>
							</td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">学 科：</td>
							<td width="152" align="left">
								<s:select id="subjectId" name="model.subject.id" list="subjectList" listKey="sjId" listValue="sjName" headerKey="1" headerValue="--选择学科--" cssStyle="width:131px" />
							</td>
							<td align="right" width="93" height="22">年 级：</td>
							<td width="214" align="left"><s:select id="grade" list="gradeMap" name="model.grade" headerKey="" headerValue="--选择年级--" cssStyle="width:131px"></s:select></td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">页 数：</td>
							<td width="152" align="left"><s:textfield id="pageCount"
								name="model.pageCount" /></td>
							<td align="right" width="93" height="22">库 存：</td>
							<td width="214" align="left"><s:textfield id="stock"
								name="model.stock" cssClass="digits"/></td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">字 数：</td>
							<td width="152" align="left"><s:textfield id="wordCount"
								name="model.wordCount" /></td>
							<td align="right" width="93" height="22">单 价：</td>
							<td width="214" align="left"><s:textfield id="price"
								name="model.price" cssClass="number"/></td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">版 次：</td>
							<td width="152" align="left"><s:textfield id="version"
								name="model.version" /></td>
							<td align="right" width="93" height="22">开 本：</td>
							<td width="214" align="left">
								<s:select id="bookSize" name="model.bookSize" list="booksizeMap" cssStyle="width:131px" />
						</tr>
						<tr>
							<td width="93" align="right" height="22">ISBN：</td>
							<td width="152" align="left"><s:textfield id="isbn"
								name="model.isbn" /></td>
							<td align="right" width="93" height="22">印刷次数：</td>
							<td width="214" align="left">
								<s:textfield id="printCount" name="model.printCount" />
							</td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">出版日期：</td>
							<td width="152" align="left">
								<input type="text" name="model.pubDate"
									   value='<s:date name="model.pubDate" format="yyyy-MM-dd"/>'
									   onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
									   class="Wdate" style="width: 128px; height: 16px"/>
							</td>
							<td align="right" width="93" height="22">印刷日期：</td>
							<td width="214" align="left">
								<input type="text" name="model.printDate"
									   value='<s:date name="model.printDate" format="yyyy-MM-dd"/>'
									   onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
									   class="Wdate" style="width: 128px; height: 16px"/>
							</td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">包装描述：</td>
							<td width="152" align="left">
								<s:select id="packDescn" name="model.packDescn" list="packdescnMap" cssStyle="width:131px" />
							</td>
							<td align="right" width="93" height="22">纸张描述：</td>
							<td width="214" align="left">
								<s:select id="paperDesc" name="model.paperDesc" list="paperdescMap" cssStyle="width:131px" />
							</td>
						</tr>
						<tr>
							<td width="93" align="right" height="22">是否置顶：</td>
							<td align="left" colspan="3">
								<input type="checkbox" name="model.onTop" id="onTop" value="1" ${model.onTop == 1?"checked":""} style="border:0px;"/>
							</td>
						</tr>
					  </table>
					</td>
					<td align="center" valign="top" style="border-left: 1px dotted #099EBD;">
					  <table width="300" height="300" border="0" cellspacing="0">
						<tr>
							<td style="height: 3px;" align="center">图书封面</td>
						</tr>
						<tr>
							<td id="photoOperSpan1">&nbsp; <img alt="封面" align="middle"
								width="220" height="240" id="imgphoto"
								src="<c:if test='${not empty model.coverPhoto}'>${ctx}${model.coverPhoto}</c:if>
							 <c:if test='${empty model.coverPhoto}'> ${ctx}/images/longtian/book_nophoto_big.gif</c:if>" />
							</td>
						</tr>
						<tr>
							<td align="center" id="photoOperSpan2"
								style="border-top: 0px dotted #099EBD; padding-top: 10px">
							<c:choose>
								<c:when test="${empty model.coverPhoto}">
									<s:file id="photo" name="photo" cssClass="FileText"
										onchange="changeImg()"></s:file>
								</c:when>
								<c:otherwise>
									<input name="button" type="button" onClick="deletePhoto()"
										value="删除封面" />
								</c:otherwise>
							</c:choose></td>
						</tr>
					  </table>
					</td>
				</tr>
			</table>
			<table width="850" align="center" style="border-top: 1px dotted #099EBD;" border="0">
			 <tr>
				<td width="88" align="right" height="22" valign="top"><b>描 述：</b></td>
				<td align="left">
				 <s:textarea id="descn" name="model.descn" cssStyle="width:750px; height:190px" />
			    </td>
			</tr>
			</table>
			</fieldset>
			<table width="100%" style="margin-bottom: 0px;">
				<tr>
					<td height="5"></td>
				</tr>
				<tr>
					<td style="text-align: center;"><s:submit value="保存"
						cssClass="button" />&nbsp;&nbsp; <s:reset value="重置"
						cssClass="button" /></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</s:form>
</div>
</div>
<script type="text/javascript">
  //删除照片
  function deletePhoto(){
    if(confirm("确定要删除该图书的封面照片吗?")){           
    	var enId = $("#bookId")[0].value;
        $.ajax({
    		url: '${ctx}/book/deletePhoto.do',
    		type: 'post',
    		dataType: 'json',
    		data: {bookId : enId},
    		success: function(rst, textStatus){
    	  		if(rst.result == "success"){
    	  		  document.getElementById("photoOperSpan1").innerHTML=
    	            "<img alt='封面照片' align='center' width='220' height='240' id='imgphoto' src='${ctx}/images/longtian/book_nophoto_big.gif'/><br/>";
    	          document.getElementById("photoOperSpan2").innerHTML=
    	           "<input type='file' id='photo' name='photo' class='FileText' onchange='changeImg()'/>";
    	  	  	}else{
    	  	  	  alert("删除封面照片失败，请与管理员联系！");
    	  	  	}
    		}
    	  });
    }
  }
  
  function changeImg(){
  	var img = document.getElementById("photo");
  	var imgphoto = document.getElementById("imgphoto");
  	imgphoto.src = img.value;
  }
  
</script>

<script type="text/javascript">
	$(document).ready(function() {
		$("#bookForm").validate();
		var bkType = document.getElementById("bkType").value;
		//alert(bkType.length);
		var boxs = document.getElementsByName("bkTypes");
		
		for(i = 0; i < boxs.length; i++){
			if (bkType.indexOf(boxs[i].value) != -1){
				boxs[i].checked = true;
			}
		}
	});
	function preFckEditor(){
		var fckEditor = new FCKeditor( 'descn' ) ;
	    fckEditor.BasePath = "${ctx}/scripts/fckeditor/";
	    fckEditor.ToolbarSet = 'BasicA';
	    fckEditor.Width = 750;
	    fckEditor.Height = 320;
	    fckEditor.ReplaceTextarea();
	}
	preFckEditor();
</script>
</body>
</html>